package com.dronff.gvm.utils;

/**
 * @author: tyf
 * @date: 2022/9/9 20:51
 * @description: todo(
 */
public class ByteUtils {
    public static int byte2int(byte[] bytes){
        int result = 0x0;
        for(int i=0;i<bytes.length;i++){
            result <<= 8;
            result |= (bytes[i] & 0xff);
        }
        return result;
    }
    public static byte[] int2bytes(int num){
        byte[] temp = new byte[4];
        int bytcount = 0;
        do{
            temp[bytcount++] = (byte) (num & 0xff);
            num >>= 8;
        }while (num!=0);
        byte[] result = new byte[bytcount];
        for(int i=0;i<bytcount;i++){
            result[bytcount-i-1] = temp[i];
        }
        return result;
    }
}
